<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<style>
    * {
        margin: 0;
        padding: 0;
        list-style: none;
        box-sizing: border-box;
    }

    .mi {
        position: relative;
        width: 223px;
        margin: 100px auto;
    }

    .mi input {
        width: 223px;
        height: 48px;
        padding: 0 10px;
        font-size: 14px;
        line-height: 48px;
        border: 1px solid #e0e0e0;
        outline: none;
    }

    .mi .search {
        border: 1px solid #ff6700;
    }

    .result-list {
        position: absolute;
        left: 0;
        top: 48px;
        width: 223px;
        border: 1px solid #ff6700;
        border-top: 0;
        background-color: #fff;
        display: none;
    }

    .result-list a {
        display: block;
        padding: 6px 15px;
        font-size: 12px;
        color: #424242;
        text-decoration: none;
    }

    .result-list a:hover {
        background-color: #eee;
    }
</style>

<body>
    <div class="mi">
        <input type="search" placeholder="小米笔记本">
        <ul class="result-list">
            <li><a>小米 11</a></li>
            <li><a>小米 手环</a></li>
            <li><a>小米 手机</a></li>
            <li><a>小米 音箱</a></li>
        </ul>
    </div>
    <script>
        // 1.获取元素
        let search = document.querySelector('input[type=search]')
        let resultList = document.querySelector('.result-list')
        // 2.事件监听 获得光标事件 focus
        search.addEventListener('focus', function () {
            // 显示下拉菜单
            resultList.style.display = 'block'
            // 文本框变色
            search.classList.add('search')
        })
        // 3.事件监听 失去光标事件 blur
        search.addEventListener('blur', function () {
            // 隐藏下拉菜单
            resultList.style.display = 'none'
            // 文本框去色
            search.classList.remove('search')
        })
    </script>
</body>

</html>